package week2.day10;

/**
 * @Author fengzihao
 * @Date 2024-04-24 14:17
 */
public class PersonTest {
    public static void main(String[] args) {
        Person person1 = new SouthPerson();
        // 此处报错，不可以这么调用
        // person1.salary;
        // person1.swim();
        SouthPerson southPerson = (SouthPerson) person1;
        System.out.println("southPerson.salary = " + southPerson.salary);
        southPerson.swim();


        Person person2 = new NorthPerson();
        // 此处报错，不能这么调用
        // person2.salary;
        // person2.swim();

        // 此处强转报错
        // class week2.day10.NorthPerson cannot be cast to class week2.day10.SouthPerson
        // (week2.day10.NorthPerson and week2.day10.SouthPerson are in unnamed module of loader 'app')
        // SouthPerson southPerson1 = (SouthPerson) person2;

        // 测试test方法
        test(new SouthPerson());
        test(new NorthPerson());


    }

    public static void test(Person person){
        person.eat();
    }
}
class Person{
    public String name;
    public int age;

    public void eat(){
        System.out.println("人都要吃饭");
    }

}
class SouthPerson extends Person{
    public double salary;

    @Override
    public void eat() {
        System.out.println("南方人喜欢吃米饭");
    }

    public void swim(){
        System.out.println("南方人喜欢游泳");
    }
}
class NorthPerson extends Person{
    public double height;

    @Override
    public void eat() {
        System.out.println("北方人喜欢吃面食");
    }
    public void drink(){
        System.out.println("北方人喜欢小酌一杯");
    }
}
